#include "stdafx.h"

#include "core/config.h"
#include "core/logger.h"

namespace natrium {
	namespace core {
		namespace po = boost::program_options;

		Config::Config():
			util::UniqueNamed("Config")
		{
		}

		Config::~Config() {
		}

		po::options_description& Config::settings() {
			return mOptions;
		}

		bool Config::load(const std::string& filename) {
			std::ifstream ifs(filename.c_str());

			if (!ifs) {
				gLog << "Failed to open config file: " << filename;
				return false;
			}
			else {
				po::store(po::parse_config_file(ifs, mOptions, true), mVariables);
				po::notify(mVariables);
				return true;
			}
		}

		void Config::parseCommandLine(int argc, char* argv[]) {
			po::store(po::parse_command_line(argc, argv, mOptions), mVariables);
			mVariables.notify();
		}

		bool Config::isAvailable(const std::string& identifier) const {
			return (mVariables.count(identifier) > 0);
		}
	}
}